#include "test.h"

namespace Test
{
    Parser::Parser()
    {
    }

    Parser::~Parser()
    {
    }

    void Parser::onCharacter(char c)
    {
        if (object.get() != 0)
            object->data.push_back(c);
    }

    void Parser::onEnterWhiteSpace()
    {
        object.reset( new Object(stWhiteSpace) );
    }

    void Parser::onLeaveWhiteSpace()
    {
        assert( object.get() != 0 );
        assert( object->type == stWhiteSpace );
    }

    void Parser::onEnterEOL()
    {
        object.reset( new Object(stEOL) );
    }

    void Parser::onLeaveEOL()
    {
        assert( object.get() != 0 );
        assert( object->type == stEOL );
    }

    void Parser::onEnterComment()
    {
        object.reset( new Object(stComment) );
    }

    void Parser::onLeaveComment()
    {
        assert( object.get() != 0 );
        assert( object->type == stComment );
    }

    void Parser::onEnterString()
    {
        object.reset( new Object(stString) );
    }

    void Parser::onLeaveString()
    {
        assert( object.get() != 0 );
        assert( object->type == stString );
    }

    void Parser::onEnterName()
    {
        object.reset( new Object(stName) );
    }

    void Parser::onLeaveName()
    {
        assert( object.get() != 0 );
        assert( object->type == stName );
    }

    void Parser::onEnterDictionary()
    {
        object.reset( new Object(stDictBeg) );
    }

    void Parser::onLeaveDictionary()
    {
        object.reset( new Object(stDictEnd) );
    }

    void Parser::onEnterArray()
    {
        object.reset( new Object(stArrayBeg) );
    }

    void Parser::onLeaveArray()
    {
        object.reset( new Object(stArrayEnd) );
    }

    void Parser::onEnterNames()
    {
        object.reset( new Object(stNamesBeg) );
    }

    void Parser::onLeaveNames()
    {
        object.reset( new Object(stNamesEnd) );
    }

    void Parser::onEnterToken()
    {
        object.reset( new Object(stToken) );
    }

    void Parser::onLeaveToken()
    {
        assert( object.get() != 0 );
        assert( object->type == stToken );
    }

    // ====================================================

    ScannerTest::ScannerTest(const char *src) : m_stream( src )
    {
    }

    ScannerTest::~ScannerTest()
    {
    }

    void ScannerTest::checkNext( ScannerType type, const std::string &data )
    {
        Parser parser;

        parser.scanNext( m_stream.rdbuf()->sgetc(), m_stream.rdbuf() );

        assert( parser.object.get() != 0 );
        assert( parser.object->type == type );
        assert( parser.object->data == data );
    }
}